package com.voicenews.model;

import java.net.URL;

import javax.xml.bind.annotation.XmlRootElement;

/**
 * @author Chunt
 * 
 *         This class is used to store all the information about a given article
 *         that is returned from an RSS feed. It is based on the RSS2.0
 *         definition and contains the variables for select core attributes in
 *         the schema
 * 
 */

@XmlRootElement
public class Article {

	private long articleId;
	private long feedId;
	private String title;
	private String description;
	private String imgLink;
	private String pubDate;
	private URL url;
	private String content;
	private String[] tags;

	/**
	 * @return the articleId
	 */
	public long getArticleId() {
		return articleId;
	}

	/**
	 * @param articleId
	 *            the articleId to set
	 */
	public void setArticleId(long articleId) {
		this.articleId = articleId;
	}

	/**
	 * @return the feedId
	 */
	public long getFeedId() {
		return feedId;
	}

	/**
	 * @param feedId
	 *            the feedId to set
	 */
	public void setFeedId(long feedId) {
		this.feedId = feedId;
	}

	/**
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * @param title
	 *            the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * @return the url
	 */
	public URL getUrl() {
		return url;
	}

	/**
	 * @param url
	 *            the url to set
	 */
	public void setUrl(URL url) {
		this.url = url;
	}

	/**
	 * @param description
	 *            the description to set
	 */
	public void setDescription(String description) {
		this.description = description;

		// parse description for any image or video links
		if (description.contains("<img ")) {
			String img = description.substring(description.indexOf("<img "));
			String cleanUp = img.substring(0, img.indexOf(">") + 1);
			this.description = this.description.replace(cleanUp, "");
			img = cleanUp.substring(img.indexOf("src=") + 5);
			int indexOf = img.indexOf("'");
			if (indexOf == -1) {
				indexOf = img.indexOf("\"");
			}
			img = img.substring(0, indexOf);
			System.out.println(img);
			this.imgLink = img;
		}
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param pubDate
	 *            the pubDate to set
	 */
	public void setPubDate(String pubDate) {
		this.pubDate = pubDate;
	}

	/**
	 * @return the pubDate
	 */
	public String getPubDate() {
		return pubDate;
	}

	/**
	 * @return the content only text of article
	 */
	public String getContent() {
		return content;
	}

	/**
	 * @param content
	 *            the contet only text to set
	 */
	public void setContent(String content) {
		this.content = content;
	}

	/**
	 * @param imgLink
	 *            the imgLink to set
	 */
	public void setImgLink(String imgLink) {
		this.imgLink = imgLink;
	}

	/**
	 * @return the imgLink
	 */
	public String getImgLink() {
		return imgLink;
	}

	/**
	 * @return the tags of article
	 */
	public String[] getTags() {
		return tags;
	}

	/**
	 * @param tags
	 *            the tags to set
	 */
	public void setTags(String[] tags) {
		this.tags = tags;
	}
}
